package xoracle

import (
	"database/sql"
	"fmt"
)


func GetOracleSchemaList(dB *sql.DB) ([]string, error) {
	sqlDbStr := "select username from sys.dba_users" // 查询所有schema
	rows, err := dB.Query(sqlDbStr)
	if err != nil {
		return nil, err
	}
	var schemaList = make([]string, 0)
	var schemaName string
	for rows.Next() {
		err := rows.Scan(&schemaName)
		if err != nil {
			fmt.Printf("scan schema failed, err:%v\n", err)
			return nil, err
		}
		schemaList = append(schemaList, schemaName)
	}
	return schemaList, nil
}


func GetOracleTbList(dB *sql.DB, schemaName string) ([]string, error) {
	sqlTbStr := fmt.Sprintf("select TABLE_NAME from all_tab_comments where owner ='%s'", schemaName)
	query, err := dB.Query(sqlTbStr)
	if err != nil {
		return nil, err
	}
	var tbList = make([]string, 0)
	var tbName string
	for query.Next() {
		err := query.Scan(&tbName)
		if err != nil {
			fmt.Printf("scan failed, err:%v\n", err)
			return nil, err
		}
		tbList = append(tbList, tbName)
	}
	return tbList, nil
}
